<?php

namespace app\adminapi\export;

use app\services\activity\ActivityService;
use Carbon\Carbon;

class ActivityExport extends BaseExport
{
    protected $header = [
        '活动标题', '有效时间', '状态', '类型', '参与门槛', '活动开启/关闭'
    ];

    public function createData(array $where)
    {
        $list = app()->make(ActivityService::class)->getAdminList($where)['list'];

        $data = [];

        $time_status_map = [
            0   =>  '未开始',
            1   =>  '进行中',
            2   =>  '已结束'
        ];

        foreach ($list as $item) {

            $expire_time = ($item['start_time'] && $item['end_time']) ? Carbon::parse($item['start_time'])->format('Y-m-d H:i:s') . '至' . Carbon::parse($item['end_time'])->format('Y-m-d H:i:s') : '';

            // 参与门槛
            $join_type = '';
            if ($item['type'] == 1) {
                $join_type = '全员参与';
            } else if ($item['type'] == 2) {
                $join_type = '用'. $item['type_jifen'] . '积分兑换';
            } else if ($item['type'] == 3) {
                $join_type = '分享满'. $item['type_people'] . '人领取';
            }


            $data[] = [
                $item['title'] ?? '',
                $expire_time,
                $time_status_map[$item['time_status']] ?? '',
                $item['cate_name'] ?? '',
                $join_type,
                $item['status'] ? '开启' : '关闭'
            ];
        }

        return $data;
    }
}